<?php
function connection($db){
    header('content-type:text/html;charset=utf8');
    $link = mysql_connect('localhost', 'root', 'root') or die('连接数据库失败' . mysql_error());
    mysql_select_db($db) or die('选库失败' . mysql_error()) ;
    mysql_set_charset('utf8');
}
function select($db,$table,$where=''){
    connection($db);
    $sql = "select * from `$table` {$where}";

    $res=mysql_query($sql);
    //$a=mysql_fetch_assoc($res);
    $arr=array();
    while($a=mysql_fetch_assoc($res)){
    //var_dump($a);echo '<br>';
    $arr[]=$a;
//     $b=1;
//     $c=1;  
//     $a=$b+$c;
 }

return $arr;
}

function del($db,$table){
    connection($db);
    $del_id=isset($_GET['id'])?$_GET['id']:'';
    $sql="delete from {$table} where id='$del_id'";
    $r=mysql_query($sql);
    if($r){
        echo "<script>alert('删除成功！');window.location.href='../articlelist/design.php'</script>";
    }else{
        echo "<script>alert('删除失败！');window.location.href='../articlelist/design.php'</script>";
}
return $r;
}
function add($db,$table,$post){
    connection($db);
    // var_dump($post);die;
$ziduanming='`'.implode('`,`',array_keys($post)).'`';
$v="'".implode("','",$post)."'";
$sql="insert into {$table}({$ziduanming}) values({$v})";
$res=mysql_query($sql);
if($res){
    echo "<script>alert('添加成功！');window.location.href='mysql.php'</script>";//window.location.href='mysql.php'
}else{
    echo "<script>alert('添加失败！');window.location.href='mysql.php'</script>";
}
return $res;

}
function alter2($db,$table,$post){
    connection($db);
    $id=isset($_POST['id'])?$_POST['id']:'';
    $name=isset($_POST['name'])?$_POST['name']:'';
    $sex=isset($_POST['sex'])?$_POST['sex']:'';
    $classid=isset($_POST['classid'])?$_POST['classid']:'';
    $sql = "update $table set `name`='$name',`sex`='$sex',`classid`='$classid' where `id`='$id'";
    $res=mysql_query($sql);
    return $res;
}

















?>